package top.aicey.ai.sparring.processor;

import top.aicey.ai.sparring.common.holder.SparringContext;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 本地陪练上下文处理器
 * @author yangyongping
 * @date 2025-01-11 2:09 下午
 */
@Component
public class LocalSparringContextProcessor implements SparringContextProcessor {

    private final static ConcurrentHashMap<String, SparringContext> LOCAL_CACHE = new ConcurrentHashMap<>();

    /**
     * 读取实例内容
     *
     * @param instanceId
     * @return
     */
    @Override
    public SparringContext get(String instanceId) {
        return LOCAL_CACHE.get(instanceId);
    }

    /**
     * 设置上下文内容
     *
     * @param context
     * @return
     */
    @Override
    public void put(SparringContext context) {
        LOCAL_CACHE.put(context.getInstanceId(),context);
    }

    /**
     * 清除上下文内容
     *
     * @param instanceId
     * @return
     */
    @Override
    public void clear(String instanceId) {
        LOCAL_CACHE.remove(instanceId);
    }

}
